﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TYBase;

namespace TYPLC.MX {
    public class MXDataItem {
        public string Address { get; set; }
        public int count { get; set; }
        public static MXDataItem FromAddress(string strAddress) {
            MXDataItem item = new MXDataItem() { count = 1, Address = strAddress };

            var indexStart1 = strAddress.IndexOf("[");
            var indexStart2 = strAddress.IndexOf("]");
            if (indexStart1 >= 0) {
                item.Address = strAddress.Substring(0, indexStart1);
            }
            if (indexStart1 >= 0 && indexStart2 >= 0) {
                item.count = strAddress.Substring(indexStart1 + 1, indexStart2 - indexStart1 - 1).AsInt();
            }
            if (item.Address.Null()) {

            }
            return item;
        }
    }
}
